﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using OrganizerLibrary.Extensions;
using OrganizerLibrary.Settings;

namespace OrganizerLibrary.Processors
{
    public class ProcessorDictionary : Dictionary<String, Func<FileSystemInfo, ProcessorBase>>
    {
        private ProcessorDictionary()
        {}

        public static ProcessorDictionary Instantiate()
        {
            return new ProcessorDictionary();
        }

        public void Process(FileSystemInfo fileInfo)
        {
            String extension = fileInfo.GetFileExtension().ToUpperInvariant();
            if(ContainsKey(extension))
            {
                ProcessorBase processor = this[extension].Invoke(fileInfo);
                processor.Process();
            }
        }

        public void ProcessUnmapped(FileSystemInfo fileInfo)
        {
            ProcessorBase processor = this[OrganizerSettings.UnmappedDirectoryConstant].Invoke(fileInfo);
            processor.Process();
        }

        public Boolean ContainsFileExtension(String extension)
        {
            return ContainsKey(extension.ToUpperInvariant());
        }

        public void AddProcessor(String extension, Func<FileSystemInfo, ProcessorBase> processorFunction)
        {
            Add(extension.ToUpperInvariant(), processorFunction);
        }
    }
}
